<?php
	class MsCorrecaoDAO{
		protected $db;

		public function __construct($db){
			$this->db = $db;
		}

		public function setDb($db){
			$this->db = $db;
		}

		public function getDb(){
			return $this->db;
		}

		public function addMsCorrecao($mc){					
			$sql = "insert into ms_correcao (ms, perc, vlr_venda_ant, vlr_venda_novo, vlr_vr_ant, vlr_vr_novo, vlr_plus_ant, vlr_plus_novo)
					values ({$mc->getMs()->getId()},{$mc->getPerc()},{$mc->getVlrVendaAnt()},{$mc->getVlrVendaNovo()},{$mc->getVlrVrAnt()},{$mc->getVlrVrNovo()},{$mc->getVlrPlusAnt()},{$mc->getVlrPlusNovo()})";			
			$res = $this->getDb()->insert($sql);
			return $res;
		}

		public function getLista($where=array(),$order=array()){
			$where = ($where ? "where ".implode(" and ", $where) : "");
			$sql = "select MS_CORRECAO, MS, PERC, VLR_VENDA_ANT, VLR_VENDA_NOVO, VLR_VR_ANT, VLR_VR_NOVO, VLR_PLUS_ANT, VLR_PLUS_NOVO, DT_CORRECAO
					from ms_correcao
					{$where}
					order by dt_correcao";
			$res = $this->getDb()->query($sql);

			$listaMc = array();
			if($res){
				$md = new MsDAO($this->getDb());

				foreach($res as $r){
					$ms = $md->getMs($r['MS']);

					$listaMc[] = new MsCorrecao($r['MS_CORRECAO'],$ms,$r['VLR_VENDA_ANT'],$r['VLR_VENDA_NOVO'],$r['VLR_VR_ANT'],$r['VLR_VR_NOVO'],$r['VLR_PLUS_ANT'],$r['VLR_PLUS_NOVO'],$r['PERC'],$r['DT_CORRECAO']);
				}
			}

			return $listaMc;
		}
	}
?>